﻿CREATE TABLE [dbo].[Employees] (
    [Id] [int] NOT NULL IDENTITY,
    [Name] [nvarchar](20) NOT NULL,
    [Gender] [nvarchar](max),
    [Description] [nvarchar](max),
    [HappinessIndex] [int] NOT NULL,
    [Picture] [nvarchar](max),
    [BirthDay] [datetime],
    CONSTRAINT [PK_dbo.Employees] PRIMARY KEY ([Id])
)
CREATE TABLE [dbo].[News] (
    [Id] [int] NOT NULL IDENTITY,
    [Title] [nvarchar](50) NOT NULL,
    [Content] [nvarchar](500) NOT NULL,
    [PublishDate] [datetime] NOT NULL,
    [EmployeeId] [int] NOT NULL,
    [NewsType] [int] NOT NULL,
    [TimeStamp] [nvarchar](max),
    CONSTRAINT [PK_dbo.News] PRIMARY KEY ([Id])
)
CREATE INDEX [IX_EmployeeId] ON [dbo].[News]([EmployeeId])
CREATE TABLE [dbo].[Departments] (
    [Id] [int] NOT NULL IDENTITY,
    [Name] [nvarchar](20) NOT NULL,
    [Description] [nvarchar](20),
    CONSTRAINT [PK_dbo.Departments] PRIMARY KEY ([Id])
)
CREATE TABLE [dbo].[TaskInitiations] (
    [Id] [int] NOT NULL IDENTITY,
    [WeekDate] [nvarchar](max),
    [TaskValue] [nvarchar](max),
    [EmployeeId] [int] NOT NULL,
    [TaskNameId] [int] NOT NULL,
    [TaskId] [int] NOT NULL,
    CONSTRAINT [PK_dbo.TaskInitiations] PRIMARY KEY ([Id])
)
CREATE INDEX [IX_EmployeeId] ON [dbo].[TaskInitiations]([EmployeeId])
CREATE INDEX [IX_TaskId] ON [dbo].[TaskInitiations]([TaskId])
CREATE TABLE [dbo].[Tasks] (
    [Id] [int] NOT NULL IDENTITY,
    [Name] [nvarchar](50) NOT NULL,
    [Decription] [nvarchar](50) NOT NULL,
    [DefaultValue] [int] NOT NULL,
    CONSTRAINT [PK_dbo.Tasks] PRIMARY KEY ([Id])
)
CREATE TABLE [dbo].[TaskCompleteds] (
    [Id] [int] NOT NULL IDENTITY,
    [CompletedValue] [int] NOT NULL,
    [Date] [datetime] NOT NULL,
    [TaskId] [int] NOT NULL,
    CONSTRAINT [PK_dbo.TaskCompleteds] PRIMARY KEY ([Id])
)
CREATE INDEX [IX_TaskId] ON [dbo].[TaskCompleteds]([TaskId])
CREATE TABLE [dbo].[Follows] (
    [Id] [int] NOT NULL IDENTITY,
    [PostId] [int] NOT NULL,
    [EmployeeId] [int] NOT NULL,
    [Comments] [nvarchar](200),
    CONSTRAINT [PK_dbo.Follows] PRIMARY KEY ([Id])
)
CREATE INDEX [IX_PostId] ON [dbo].[Follows]([PostId])
CREATE INDEX [IX_EmployeeId] ON [dbo].[Follows]([EmployeeId])
CREATE TABLE [dbo].[Posts] (
    [Id] [int] NOT NULL IDENTITY,
    [Title] [nvarchar](50) NOT NULL,
    [CreateDate] [datetime] NOT NULL,
    [Content] [nvarchar](200) NOT NULL,
    [Type] [nvarchar](max),
    [EmployeeId] [int] NOT NULL,
    [PostsTypeId] [int] NOT NULL,
    CONSTRAINT [PK_dbo.Posts] PRIMARY KEY ([Id])
)
CREATE INDEX [IX_EmployeeId] ON [dbo].[Posts]([EmployeeId])
CREATE INDEX [IX_PostsTypeId] ON [dbo].[Posts]([PostsTypeId])
CREATE TABLE [dbo].[PostsTypes] (
    [Id] [int] NOT NULL IDENTITY,
    [Name] [nvarchar](50) NOT NULL,
    [Description] [nvarchar](500),
    CONSTRAINT [PK_dbo.PostsTypes] PRIMARY KEY ([Id])
)
CREATE TABLE [dbo].[DepartmentEmployees] (
    [Department_Id] [int] NOT NULL,
    [Employee_Id] [int] NOT NULL,
    CONSTRAINT [PK_dbo.DepartmentEmployees] PRIMARY KEY ([Department_Id], [Employee_Id])
)
CREATE INDEX [IX_Department_Id] ON [dbo].[DepartmentEmployees]([Department_Id])
CREATE INDEX [IX_Employee_Id] ON [dbo].[DepartmentEmployees]([Employee_Id])
ALTER TABLE [dbo].[News] ADD CONSTRAINT [FK_dbo.News_dbo.Employees_EmployeeId] FOREIGN KEY ([EmployeeId]) REFERENCES [dbo].[Employees] ([Id]) ON DELETE CASCADE
ALTER TABLE [dbo].[TaskInitiations] ADD CONSTRAINT [FK_dbo.TaskInitiations_dbo.Employees_EmployeeId] FOREIGN KEY ([EmployeeId]) REFERENCES [dbo].[Employees] ([Id]) ON DELETE CASCADE
ALTER TABLE [dbo].[TaskInitiations] ADD CONSTRAINT [FK_dbo.TaskInitiations_dbo.Tasks_TaskId] FOREIGN KEY ([TaskId]) REFERENCES [dbo].[Tasks] ([Id]) ON DELETE CASCADE
ALTER TABLE [dbo].[TaskCompleteds] ADD CONSTRAINT [FK_dbo.TaskCompleteds_dbo.Tasks_TaskId] FOREIGN KEY ([TaskId]) REFERENCES [dbo].[Tasks] ([Id]) ON DELETE CASCADE
ALTER TABLE [dbo].[Follows] ADD CONSTRAINT [FK_dbo.Follows_dbo.Posts_PostId] FOREIGN KEY ([PostId]) REFERENCES [dbo].[Posts] ([Id]) ON DELETE CASCADE
ALTER TABLE [dbo].[Follows] ADD CONSTRAINT [FK_dbo.Follows_dbo.Employees_EmployeeId] FOREIGN KEY ([EmployeeId]) REFERENCES [dbo].[Employees] ([Id]) ON DELETE CASCADE
ALTER TABLE [dbo].[Posts] ADD CONSTRAINT [FK_dbo.Posts_dbo.Employees_EmployeeId] FOREIGN KEY ([EmployeeId]) REFERENCES [dbo].[Employees] ([Id])
ALTER TABLE [dbo].[Posts] ADD CONSTRAINT [FK_dbo.Posts_dbo.PostsTypes_PostsTypeId] FOREIGN KEY ([PostsTypeId]) REFERENCES [dbo].[PostsTypes] ([Id]) ON DELETE CASCADE
ALTER TABLE [dbo].[DepartmentEmployees] ADD CONSTRAINT [FK_dbo.DepartmentEmployees_dbo.Departments_Department_Id] FOREIGN KEY ([Department_Id]) REFERENCES [dbo].[Departments] ([Id]) ON DELETE CASCADE
ALTER TABLE [dbo].[DepartmentEmployees] ADD CONSTRAINT [FK_dbo.DepartmentEmployees_dbo.Employees_Employee_Id] FOREIGN KEY ([Employee_Id]) REFERENCES [dbo].[Employees] ([Id]) ON DELETE CASCADE
CREATE TABLE [dbo].[__MigrationHistory] (
    [MigrationId] [nvarchar](255) NOT NULL,
    [Model] [varbinary](max) NOT NULL,
    [ProductVersion] [nvarchar](32) NOT NULL,
    CONSTRAINT [PK_dbo.__MigrationHistory] PRIMARY KEY ([MigrationId])
)
BEGIN TRY
    EXEC sp_MS_marksystemobject 'dbo.__MigrationHistory'
END TRY
BEGIN CATCH
END CATCH
INSERT INTO [__MigrationHistory] ([MigrationId], [Model], [ProductVersion]) VALUES ('201211030806107_CreateDB', 0x1F8B0800000000000400DD5D5B6F1BB9157E2FD0FF20E8A95D60ADC4D900DB40DE4562D95DA3EB24889CEDA3414BB43CC85CD4192AB57E5B1FFA93FA174ACE95F7DB5CE597C01A928787871F0FC943F2CBFFFEF3DFE5AFCF5138FB0ED32C48E28BF9EBB357F3198C37C936887717F3037AFCF1E7F9AFBFFCF94FCBAB6DF43CFBA3CAF786E4C325E3EC62FE84D0FEDD62916D9E6004B2B328D8A449963CA2B34D122DC036599CBF7AF5B7C5EBD70B8845CCB1ACD96CF9E510A32082F90FFCF3328937708F0E20BC4DB630CCCAEF38659D4B9D7D0411CCF660032FE6BFADCEF24CF3D9FB3000B8FE350C1FE7B3FD4FEFBE66708DD224DEADF7000520BC3BEE214E7F0461064B6DDFED7FB255F8D539517801E23841585C127B35785E370537E60A371A1D895A79832EE657D13E4C8E10D2B970BE7FC023F3017FFA9C267B98A2E317F85896BDD9CE670BB6DC822F5817A3CA90EAF15F317A733E9F7D3C84217808616D256CC6354A52F87718C31420B8FD0C1082694CCAC25C7DA156AE0EF26F550BEE0E8CA3F9EC3A7886DBDF61BC434F754DB7E0B9FA728EC1F4350E30EA7019941EA044317DA558DD2D4C1DABC57F6AEA2D7EEBAB5DC16C9306FB021D03D7FD1BD8EF831866D90D6EFA735D3D1E0C6724E9587E7634E4E760830EA96B07B66FCD8720454F2B70AC2A5E61ECDD059159CE47F03DD8E5E393C721FC77369F7D81619E983D05FBD23AD5A0BB2F725CA749F42509A9D19827DCAF9343BA21864864A97720DD4164AFCD0AEE418A223C84E44A35E9F755458C6EB2F45A894A4569A6AA1DB69ADE81EC9B5C4792721307D8B59284BA0A5A4D45164153553E5765AF93304C14FD5CA449D5E49204F5F874995ACB45E3CEB54E3E87D90B72F077010A5D1DC4DBD61E1E2F1110D6CFB9DED6157F3E3C8441F6441C92CE3959C9AA0065EE26C31C8B2145CA335EBFF9E8288D34658D40B4EFDFEB2B0772334AFD3D363F8AE5FEDC6B0C379EF5258DE451966AFE6B266DDD7E70EB7032E6D70BDA19DB0B84ECA4F99280F84F08BFD10E76B0652731E91F203C0C5F735753016901F9AB0B39CE32FCDC798B75243FC84CEB4D9745AF52D77B6EE0717A72C9D2B52E9FA7D564942BFB8246BFC734D47E3DB9829EB35017553F82438818BFD376C0114C5C2618FE10F7807AFB5667B92F10CF22994D950299CBE2B3B9A4475237234EE61554A3D27BC4D52D7F4943AF6E940F18795877B143EA761AD2BA75A7B120839862B87821AC8838BC24687D4E32D47651D2D52209F754197A73DC7074B7E320E69042912464F77520AB41219320386336D5D50F6BD7670E81337E58A8026B5E63226FE24B1A122345CE5288B5EDC43BFB05E1F4C3C86E5AA0835DA7B645CB714C040CB4BF2A5C836CF8B229C2E8E5925D3751753BD55A91D4FB625CF36A3549725F47A577794A60E97EE5A6E29DB3BF9BCBCDF6825CDD487B3ADFD0A2FE9CC07DA6D760CD6E0848F126192276883B4414DEE8D3E19BEC3A04BBE692C457728C1E1EB1C96880B00DBF85D1034C2B61C1EE09AB916F1F2EE6AF042B31996F83EDD7FD9E9CD397F95F1BF3D759CFF5597FC78BE72AEB1BD12C85013446690E4F5A9BA409FC16C71576B6B98A20EED17873640A190CD4547579088B737BB9B9E436789F65C9A6D81F73F3CABDE4D0F22ADECEB407E5CD515433F7DC62BD827D186C302E4973788FF6295E41B2879ABDDFA0FC66D125C836602B0E37DC80AD9D3EF5ECC11E8DF1BAFC205481BD2A4C897B03215EE8642805418C44171CC49B600F429D2DB842969E9BB4B216CFA7E0AE26775C62A46BB34DBDF4AA46ACBFAE86B3BEC936CB0505263DC6A4A72BAAAED51FB5343D4C1DD019FBD9205D821F159E7FE04799B51154317095A6C68078A32C1F3BB33787F1F6C6C023DC6B401A1A31C0D034F4D5490C5249804C871A55B48C456513427504A52A30CD8A9F2616E5BA0F044379BFD8545E056247431F7F06A0C387F240604080E8355240D6C54F7B2350619D8120A8B0C4E431C84551549DAD0AA934FD5CEEF5EC3D9E220C7312B3AF5CF701A026EF8793986BF9B0801617B2180187B5621F3B88AB5346EE9CE1EF8F36D12243C14D6CB84DCD4C387844D756C53CF56E4808801A7AB64FA08987618D32E5016A8F38E34D319853E35A6D8BB1D1E0C59F1FAAFA547998E8DEAB6AA127357B2A941F00698ABE98E0FC59C4B8C949242ED1C4A157AB0FF9E9E4337F43BBC8BF8648BCFADB84CB056408F86285140145A17CF1D95096790A2488A003590641ECC25A268CDF6258085489B12A4CDF40934AA122000671F5899C20A7F2090601E5EC24142FBF5B94CEDF8FAA24148B2C4E0A05591170E5EB052A8FF479033F824C61F75A7306DAC2403445CB293152142FD8B659B45B7E8B5E6CBE391E6C1F11A65AC10C338D39B431601BE37A984679035AB48E55A0D829544CB549F0201A3B9982C33D9A8ABFA927B7922E5C691BB0E46C43FB33836914214A4E605716112EC8CA4DA28DA15947D14C6DB00E7ED923CFC32CFCAD17D122BA888E4D4C87525F3A89D804717A1A25C2CD0245EB555106AB3803D7FE727A34D940121D3019D2BBF7EB4583AAF3A57B5E8B5DAF47D7F37B554A44AD66EB660B5735C5866B776356FB31B3E6563BB096D0AF6EB7D42BFF3A6DB9285842CA0FCB85824E64799B5326EC287A91F2CB6C5D708B5CFEB87667F9880A198B0D032B7E9F52D7849214EC20974AAE566EE17590666805107800E4E6C9E53612B259EC73AA9AF8ED8ED863D5BAB62A41FEAEB65305C9CA990A368DEDAE7173C8EA296F199474B2587446785D400852C9C5B4CB243C44B17A4FAB2E5D5C39A3CB175FEC25542C22B48CEA9BBD14E6161A2D8A49B097C7137DD022F9347BA935D1072DAEFE682FA721EEA005355F4549CB05871C216620205308B6B050B71A088ACD95C5189095B4C0BFBC583FD82F6F96D302CA4FF632EACBDDB494FAA303B268C204065D7482BD3C3ABE448BD3C59DD4D29A8B7E8CA7A8BFBAD8BCA64D60ED5E7F9E0CF6E9BDB0D71050F11FE4124C03415778AA5381AF131FA983F9ED945727EB378B161D6D12D04F6737E401B48CE6ABC3886ED8009811DD7C1ECB6BD1AFFC79D5AAEF6ED26492E4524684740B207BC2F7943C94CA41F92C32D937E9AC3C3A6552F0A0C273DE38513CEBB6068CA67C3FC8E19F6CB3AB3536CDA1FF0507EAE33C27EF54D4F11F0BB8C8DE685BE14455B01F805467FFCCD25B711F402DA5DBF9AB7980CDC155713E331A4054B1510B78488B5AA043516EC21B45EA4131D39DD4F7E1B79DE2A6CE7543D72DE4996B5EFC5854DEFF1A15F84544DF1FFCE223D65C80D50090979DEEE26B9ADB43367AAE0A02D0E7F1DACD3E9D51BDABD71D2D286970C5C37BD158565D4F8994DF40A2B4F05450790DCB4AC1FA20C44D3DFE2844EC6FE14484CF52A3AD3E19E14E4096E5698499755D389E28B2CC6758F7EFC1961C4DAC8F1982D119C970B6FE57781906B907AF32DC82387884D8C924DF609C9342FCCC51B87BD0AB2FB26C1B4E95633D20CD37BEA377A57E05CDC3FAF83B48374F201558325BB1A75752FF1281E7BF76C088DE4A9E9CE53CB76C3B66F3565AF16CE55BDCB7C8C8563E71C6E85EE0CA50DE48F1FAD61DAF1C0D8D42ACBB5C09D5B3AC673DA9AB7C40CB133DFBC810E89D1DA07F1204C927E36735CE5123BA45AF8CCD18DC4BCFF064C1AD3CB94000DC4A5A37835EA4F4F595E22261E2F4B3E30C728FC9492496ED4EB2C81BDB71BF8E4872DA4B07CBF94D7D8653278B82DEC6E458F4A1BD741ACB1CEAD359DDF8619E355431577735598F44777942CB7E81C8D27B20DAEC20CE3D7610F45A7D022B0909F364874E6744E2C2135A0DD82DF9DF76E6464C7159BBEE314555D5CF4025F9CD3DCB55D7DEF33B8951D9B62D3FDE989C78C5233EE16D6AAF1C78433C54565CC61DFD59727B8AB729A0867F56A6794B7CF248325E779C28A65C88B1C6A4C01A13478A1B8053C0D0E8C46A0EB47E63C287A20A5093089C3C7874D70F27861D07D6A0D168822A6E08095D447FC440C3F1B3BC1CEE9F292C768606CB908B1B07BC8CBEA8B1645A9C02642CBDDB0902C6DE934D032F2A260319FDC0F81489C333224E0B33E3731E5ADF3C9452035972CDF7042149484FAE8F254FBD2FB8B4AF403B4797F982A957E47234B0C96E914E6C7A9B0AD0869CF83C6166B8D53B10EDA1C81AC277AD9CFC50CB7D585CEDBD986F1F12DCFD45D45CCDD8C257A1A546948976244D347026CA6AD050C11948152D381565159AD8AD64952A79175515D889A5822552F954BAAA22350B9A82B55143DA28AB434587C40B37303ACA44DB933D964B42B9F0224D5941F16EC61EC29A5128CBA487B47A640EC34629257692B844FE688A2AD511E164AFAC8AFECD957B141961423726E8851B50507B524DEE8120D2BDC182A795BC116FDFDC6E89EE1C99ED58F74EBF6D6EDFB04EA9ECFC476B9F4DEC90A2D2BF8196FD3E19124A5155F9BBDE419AA8251FB6A336563C7754841DA836A899C18D7B38A91425D9794766A9781F2DCD227F64D909E4FB3489032DA5F8D812EF070F31B9C058FC5AC12CD835229658660C37CC4EB0CE73133F26D5AE94D3A8CAC25D8DBA85086CF136F17D8A8247B041387903B32CFFEF71CBFF35F42A7A80DB9BF8D301ED0F083719460F21C3E14736B6BAFA73EE4D56E7E5A7FCF65BD64513B09A01B9F3F929FE7008C2E63F87BD96DCE95288203BE6F2CE20E94B44EE0EEE8EB5A48F496C29A8345FBDD1BF83183C5858F6295E83EF50AD9BD986ACC596AB00EC521065A58CA63CFE89E1B78D9E7FF93FA2500420CA990000, '5.0.0.net45')
